<template>
	<div id="Home">
		<home-header :city="city"></home-header>
		<home-swiper :swiperList="swiperList"></home-swiper>
		<home-icons></home-icons>
		<home-recommend :recommendList="recommendList"></home-recommend>
		<home-weekend :weekendList="weekendList"></home-weekend>
	</div>
</template>

<script>
	import HomeHeader from './components/Header'
	import HomeSwiper from './components/Swiper'
	import HomeIcons from './components/Icons'
	import HomeRecommend from './components/Recommend'
	import HomeWeekend from './components/Weekend'
	//使用axios发送ajax请求
	import axios from 'axios'
	export default {
		name: 'Home',
		data() {
			return {
				msg: '我的home页面',
				city: '城市',
				swiperList: [],
				recommendList: [],
				weekendList: []
			}
		},
		components: {
			HomeHeader: HomeHeader,
			HomeSwiper: HomeSwiper,
			HomeIcons: HomeIcons,
			HomeRecommend: HomeRecommend,
			HomeWeekend: HomeWeekend
		},
		methods: {
			getHomeInfo() {
				//在config 目录下的 index.js中配置 转发代理，当我们请求 /api开头的地址时，自动代理转发到/static/mock 路径
				axios.get('/api/index.json').then(this.getHomeInfoSucc);
			},
			getHomeInfoSucc(res) {
				//console.log(res);
				res = res.data;
				console.log(res);
				if (res && res.ret) {
					this.city = res.data.city;
					this.swiperList = res.data.swiperList;
					this.recommendList = res.data.recommendList;
					this.weekendList = res.data.weekendList;
				}
			}
		},
		mounted() {
			this.getHomeInfo();
		}
	}
</script>

<style>

</style>
